package cn.xcstudenth5.zhuocan.scollviewandwebview;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.daquexian.flexiblerichtextview.Attachment;
import com.daquexian.flexiblerichtextview.FlexibleRichTextView;
import com.daquexian.flexiblerichtextview.Tokenizer;

import java.util.ArrayList;
import java.util.List;

import io.github.kexanie.library.MathView;

/**
 * Created by 赵航 on 2020/7/17.
 * WeChat: zhao--hang--
 */
public class RichTextView extends Fragment {

    private View     mMathLayout;
    private MathView mFormulaOne;
    String tex = "This come from string. You can insert inline formula:" +
            " \\(ax^2 + bx + c = 0\\) " +
            "or displayed formula: $$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$$";
    String two = "<p>解：<span class=\\\"ql-formula\\\" data-value=\\\"\\\\left(2a\\\\right)^3.A=8a^5\\\\\\\\\\\\;8a^3.A=8a^5\\\\\\\\A=8a^5\\\\div8a^3\\\\\\\\A=a^2\\\">$$\\\\left(2a\\\\right)^3.A=8a^5\\\\\\\\\\\\;8a^3.A=8a^5\\\\\\\\A=8a^5\\\\div8a^3\\\\\\\\A=a^2$$</span> ． </p> \\n\\r<p>故选A．</p> \\n\\r<p>先计算积的乘方，再根据单项式乘以单项式的逆运算即可．</p> \\n\\r<p>本题考查了单项式乘以单项式，解题的关键是注意字母指数的变化．</p>";
    String three = "<div>在边长为a的正方形中挖去一个边长为b的小正方形（a＞b）（如图甲），把余下的部分拼成一个矩形（如图乙），" +
            " \\(ax^2 + bx + c = 0\\) " +
            "or displayed formula: $$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$$"+
            "根据两个图形中阴影部分的面积相等，可以验证（　　）</div><div><img src=\"http://xcimg.zhuocan.com.cn/02/201809/2/20181005094844775728.png\"><br></div>";
    private FlexibleRichTextView mRichTextView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mMathLayout = inflater.inflate(R.layout.fragment_rich_view, null);
        init(mMathLayout);
        return mMathLayout;
    }

    private void init(View mathLayout) {
        mRichTextView = (FlexibleRichTextView)mathLayout.findViewById(R.id.id_rich_tv);
//        String richText = "[h][center]hi![/center][/h]" +
//                "[quote]This is quote[/quote]" +
//                "[code]print(\"Hello FlexibleRichTextView!\")[/code]" +
//                "Hello FlexibleRichTextView!\n" +
//                "This is LaTeX:\n" +
//                "$e^{\\pi i} + 1 = 0$";
        mRichTextView.setText(three);

//        List<Attachment> attachments = new ArrayList<>();
//        attachments.add(new ExampleAttachment("Android Image", "53ce1", true, "http://tse1.mm.bing.net/th?id=OIP.M24baa78c1fb80a71891ce775d11e038ao0&w=166&h=166&c=7&qlt=90&o=4&pid=1.7"));
//        attachments.add(new ExampleAttachment("Here is a link", "bc41a", false, "https://google.com"));
//
//        Tokenizer.setCenterStartLabels("<center>");
//        Tokenizer.setCenterEndLabels("</center>");
//        Tokenizer.setTitleStartLabels("<h>");
//        Tokenizer.setTitleEndLabels("</h>");
//
//        mRichTextView.setText("<h><center>hi!</center></h>" +
//                        "[quote]This is quote\n" +
//                        "second line\n" +
//                        "third line\n" +
//                        "fourth line[/quote]" +
//                        "Here is an attachment:[attachment:53ce1]" +
//                        "[code]print(\"Hello FlexibleRichTextView!\")[/code]" +
//                        "Hello FlexibleRichTextView!\n" +
//                        "This is LaTeX:\n" +
//                        "$e^{\\pi i} + 1 = 0$\n" +
//                        "This is table:\n" +
//                        "| First Header  | Second Header |\n" +
//                        "| --- | --- |\n" +
//                        "| Content Cell  | Content Cell  |\n" +
//                        "| Content Cell  | Content Cell  |\n" +
//                        "An attachment is shown at the bottom: \n",
//                attachments);
    }
}
